cmake_minimum_required(VERSION 3.1)
project(tcpserver C)
find_package ( Threads REQUIRED )
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
macro(use_c99)
    if (CMAKE_VERSION VERSION_LESS "3.1")
        if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
            set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
        endif ()
    else()
        set(CMAKE_C_STANDARD 99)
    endif ()
endmacro(use_c99)

set(CMAKE_C_STANDARD 99)
set(project_name, tcpserver)
include_directories("src/core")
include_directories("src/hash")
include_directories("src/net")
include_directories("src/net/tcp")
include_directories("src/utils")

IF (WIN32)
    link_libraries(ws2_32 wsock32)
ENDIF ()

set(core
        src/core/unix/tcp_log.c
        src/core/unix/tcp_thread.c
        src/core/unix/tcp_times.c
        src/core/unix/tcp_string.c
        src/core/unix/tcp_alloc.c
        src/core/unix/tcp_file.c)
set(utils
        src/utils/lstring.c)
set(hash
        src/hash/lock.c
        src/hash/container.c
        src/hash/dts.c
        src/hash/hash.c
        src/hash/md5.c
        src/hash/sha.c
        src/hash/tree.c
        src/hash/hash_util.c
        src/hash/zmalloc.c)

set(net
        src/net/tcp_socket.c
        src/net/tcp_socket.c
        src/net/tcp_connect.c
        src/net/tcp_epoll.c
        src/net/tcp_poll.c
        src/net/tcp_select.c
        src/net/tcp/tcp_handler.c
        src/net/tcp/tcp_request.c)
set(main
        tcpserver.c
        ${core}
        ${utils}
        ${hash}
        ${net})
add_executable(${PROJECT_NAME} ${main} test.c)
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
use_c99()